import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../../../../utils/component/component.dart';
import '../../../../../../utils/component/selected_tag_view.dart';
import '../../../../../../utils/util.dart';
import '../../main/widgets/header.dart';
import '../../main/widgets/pro_brife.dart';
import 'index.dart';
import 'widgets/widgets.dart';

class ProOpenStep2Page extends StatelessWidget {
  ProOpenStep2Page({Key? key}) : super(key: key);
  final controller = Get.put(ProOpenStep2Controller());
  // 主视图
  Widget _buildView() {
    return ListView(
      padding: EdgeInsets.only(bottom: 80.r),
      children: [
        ComBriefWidget(),
        Container(
          margin: EdgeInsets.symmetric(horizontal: 16.r, vertical: 10.r),
          padding: EdgeInsets.all(16.r),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(4.r),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                '企业类别',
                style: TextStyle(
                  color: ColorsUtil.title,
                  fontSize: 14.sp,
                ),
              ),
              SizedBox(
                height: 10.r,
              ),
              SelectTagView(
                items: const ['国企', '央企', '民企', '外企'],
                initIndexs: const [0],
                isFixed: false,
                height: 30.r,
                width: 50.r,
                spacing: 10.r,
                selectedTextStyle: TextStyle(
                  color: Colors.white,
                  fontSize: 14.sp,
                ),
                selectedTagBgColor: ColorsUtil.blue,
                tagBgColor: ColorsUtil.bg,
                textStyle: TextStyle(
                  color: ColorsUtil.title,
                  fontSize: 14.sp,
                ),
              ),
            ],
          ),
        ),
        Container(
          margin: EdgeInsets.symmetric(horizontal: 16.r),
          // padding: EdgeInsets.fromLTRB(16.r, 0, 16.r, 16.r),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(4.r),
          ),
          child: BrnTextSelectFormItem(
            title: "企业来源地",
            hint: controller.state.comFrom ?? '请选择企业来源地',
            onTip: () {},
            onAddTap: () {},
            onRemoveTap: () {},
            onTap: () {
              controller.actionChooseCity();
            },
          ),
        ),
        Container(
          margin: EdgeInsets.symmetric(horizontal: 16.r, vertical: 10.r),
          // padding: EdgeInsets.fromLTRB(16.r, 0, 16.r, 16.r),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(4.r),
          ),
          child: Column(children: [
            BrnTextInputFormItem(
              title: "企业联系人",
              hint: "请输入联系人",
              onChanged: (newValue) {
                controller.state.contacts = newValue;
              },
            ),
            BrnTextInputFormItem(
              title: "联系电话",
              hint: "请输入联系电话",
              onChanged: (newValue) {
                controller.state.phone = newValue;
              },
            ),
          ]),
        ),
        Container(
          margin: EdgeInsets.symmetric(horizontal: 16.r, vertical: 10.r),
          padding: EdgeInsets.all(16.r),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(4.r),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                '要素保障（多选）',
                style: TextStyle(
                  color: ColorsUtil.title,
                  fontSize: 14.sp,
                ),
              ),
              SizedBox(
                height: 10.r,
              ),
              SelectTagView(
                items: controller.state.factors
                        ?.map((e) => e.name ?? '')
                        .toList() ??
                    [],
                initIndexs: [],
                isFixed: true,
                height: 30.r,
                // width: 50.r,
                spacing: 10.r,
                selectedTextStyle: TextStyle(
                  color: Colors.white,
                  fontSize: 14.sp,
                ),
                selectedTagBgColor: ColorsUtil.blue,
                tagBgColor: ColorsUtil.bg,
                textStyle: TextStyle(
                  color: ColorsUtil.title,
                  fontSize: 14.sp,
                ),
                onTap: (p0) {
                  controller.setupSelectedFactors(p0);
                  controller.update();
                },
              ),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: controller.state.selectedFactorls
                        ?.map(
                          (e) => Container(
                            padding: EdgeInsets.only(top: 10.r),
                            alignment: Alignment.centerLeft,
                            width: Get.width,
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  e.name ?? '',
                                  style: TextStyle(
                                      color: ColorsUtil.title, fontSize: 15.sp),
                                ),
                                TextField(
                                  decoration: InputDecoration(
                                      hintText:
                                          '请输入${e.name ?? ''}方面的企业诉求或保障计划',
                                      hintStyle: TextStyle(
                                        color: ColorsUtil.placeholder,
                                        fontSize: 13.sp,
                                      )),
                                )
                              ],
                            ),
                          ),
                        )
                        .toList() ??
                    [],
              ),
            ],
          ),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ProOpenStep2Controller>(
      builder: (_) {
        return Scaffold(
          body: SafeArea(child: _buildView()),
        );
      },
    );
  }
}
